package com.atguigu.controller;

import com.atguigu.pojo.Schedule;
import com.atguigu.service.ScheduleService;
import com.atguigu.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("schedule")
public class ScheduleController {
    @Autowired
    private ScheduleService service;
    @GetMapping
    public Result getAll(){
        List<Schedule> all = service.getAll();
        return Result.add(all);
    }
    @DeleteMapping("{id}")
    public Result removeById(@PathVariable Integer id){
        service.removeById(id);
        return Result.add(null);
    }
    @PutMapping
    public Result changeSchedule(@RequestBody Schedule schedule){
        service.updateSchedule(schedule);
        return Result.add(null);
    }
    @PostMapping
    public Result addResult(@RequestBody Schedule schedule){
        service.saveSchedule(schedule);
        return Result.add(null);
    }
}
